<?php
/**
 * Created by PhpStorm.
 * User: liang
 * Email:1050187159@qq.com
 * Date: 8/9/2018
 * Time: 8:16 PM
 */
namespace Admin\Controller;

use Think\Controller;

class PublicController extends BaseController
{
    private $manager = null;

    public function _initialize()
    {
        $this->manager = D('Manager');
    }

    public function login()
    {
        if (IS_POST) {
           $account = I('post.account');
           $password = I('post.password');
           $result = $this->manager->login($account, $password);
           if ($result){
               //刷新用户上次登录的时间
               $this->manager->last_time = time();
               $this->manager->save();

               $this->ajaxReturn('true');
           } else {
               $this->ajaxReturn($this->manager->getError());
           }
        }

        $this->display('Public/login');
    }

    //退出登录
    public function logout()
    {
        session('id', null);
        session('account', null);
        $this->redirect('/Admin/Public/login');
    }
}